﻿namespace Joy.Erp.Ufida.Core
{
    public static class UrlExtensions
    {
        public static string AppendSegments(this string baseUrl, string segments)
        {
            return string.Format("{0}/{1}", baseUrl.TrimEnd('/'), segments.TrimStart('/'));
        }

        public static string AppendParamsUrl(this string baseUrl, string paramsUrl)
        {
            if (baseUrl.IndexOf('?') < 0)
            {
                return string.Format("{0}?{1}", baseUrl.TrimEnd('/'), paramsUrl.TrimStart('?'));
            }
            else
            {
                return string.Format("{0}&{1}", baseUrl.TrimEnd('&'), paramsUrl.TrimStart('&'));
            }
        }

        public static string AppendParam(this string baseUrl, string key, string value)
        {
            if (baseUrl.IndexOf('?') < 0)
            {
                return string.Format("{0}?{1}={2}", baseUrl.TrimEnd('/'), key, value);
            }
            else
            {
                return string.Format("{0}&{1}={2}", baseUrl.TrimEnd('&'), key, value);
            }
        }
    }
}
